package sortedArrayToBST;

public class Solution {


    public class TreeNode {
          int val;
          TreeNode left;
          TreeNode right;
         TreeNode() {}
          TreeNode(int val) { this.val = val; }
         TreeNode(int val, TreeNode left, TreeNode right) {
             this.val = val;
             this.left = left;
             this.right = right;
         }
    }
    public TreeNode sortedArrayToBST(int[] nums) {
        return travle(nums,0,nums.length-1);
    }
    private TreeNode travle(int[]nums,int left,int right){
        if(left>right){
            return null;
        }
        int mid = (left+right)>>1;
        TreeNode root = new TreeNode(nums[mid],travle(nums,left,mid-1),travle(nums,mid+1,right));
        return root;
    }

}
